from bcat.rpc.server.server import AbstractServer

from flask import Flask
from typing import Any, Dict

class FlaskServer(AbstractServer):
    def __init__(self, url: str, name: str):
        super().__init__(url)
        self.__name = name
        self.__app = Flask(self.__name)

    def name(self):
        return self.__name

    def register(self, rule: str, f: Any) -> bool:
        self.__app.add_url_rule(rule, view_func=f, methods=['POST'])
        return True

    def unregister(self, rule: str) -> bool:
        print("TODO:unregister")
        return False

    def clear(self) -> None:
        #TODO:
        print("TODO:unregister")

    def values(self) -> Dict[str, Any]:
        #TODO:
        print("TODO:unregister")
        return super().values()

    def run(self) -> bool:
        self.__app.run(debug=True)
        return True
